<?php

Loader::using("ext::libs::phpUI::impl::jQuery::util::DependencyManager");

class CitiesDependency extends DependencyManager {

    public function getConstraintClass() {
        return "cities";
    }

    protected function getManagerClass() {
        return "CitiesManager";
    }

    public function renderCallback() {
        $url = ModulesContext::instance()->getRouting()->getBaseURL();
        return " function(independentId, dependents){
                BASE_URL = '$url';
                var val = $('#' + independentId).val();
                var deps = dependents;
                
                for(var i in dependents){
                    if(typeof dependents[i] != 'function'){
                        $('#' + dependents[i].dependent).html($('<option>').html('- Elegir -'));
                    }
                }
        
                var locaciones = new Locaciones();
                locaciones.success =  function (data){
                    var options = '<option> - Elegir - </option>';
                    for(var i in data){
                        if(typeof data[i] != 'function') {
                            options += '<option value=\"' + data[i].Nombre + '\">';
                            options += data[i].Nombre;
                            options += '</options>';
                        }
                    }
                    for(var i in deps){
                        if(typeof deps[i] != 'function'){
                            $('#' + deps[i].dependent).html(options);
                        }
                    }
                }
                locaciones.GetMunicipioByNombreDepartamento(val);
                return true;
            }";
    }

    public function getEvent() {
        return "change";
    }

}

?>